package com.google.code.chaotic.client;

import com.allen_sauer.gwt.log.client.Log;
import com.google.code.chaotic.dto.CommuterDto;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Welcome implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		Log.setUncaughtExceptionHandler();

		DeferredCommand.addCommand(new Command() {
			@Override
			public void execute() {
				deferedModuleLoad();
			}
		});
	}

	private void deferedModuleLoad() {
		RegistrationPanel dockPanel = new RegistrationPanel();
		final RootPanel rootPanel = RootPanel.get("root");
		rootPanel.add(dockPanel);
		dockPanel.requestFocus();

		Window.addResizeHandler(new ResizeHandler() {
			@Override
			public void onResize(ResizeEvent event) {
				maximizeRootPanel(rootPanel);
			}
		});
		maximizeRootPanel(rootPanel);
	}

	private void maximizeRootPanel(RootPanel panel) {
		panel.setPixelSize( //
				Window.getClientWidth(), //
				Window.getClientHeight());
	}

}
